package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.activity.village.VillageListAcitivity;
import com.jiangxiaofei.citycloud.bean.VillageMenuBean;

import java.util.List;

/**
 * Created by JiangXFei on 2017/8/16.
 */

public class VillageMenuAdapter extends RecyclerView.Adapter<VillageMenuAdapter.MyViewHolder> {
    Context mContext;
    List<VillageMenuBean> menuList;

    public VillageMenuAdapter(Context mContext, List menuList) {
        this.mContext = mContext;
        this.menuList = menuList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_village_menu, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tvMenu.setText(menuList.get(position).getName());
        Glide.with(mContext).load(menuList.get(position).getImg()).into(holder.imgMenu);
        holder.imgMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, VillageListAcitivity.class);
                intent.putExtra(VillageListAcitivity.TYPE, menuList.get(position).getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return menuList.size();
    }


     class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView imgMenu;
        TextView tvMenu;

        public MyViewHolder(View itemView) {
            super(itemView);
            imgMenu = itemView.findViewById(R.id.item_village_img_menu);
            tvMenu = itemView.findViewById(R.id.item_village_tv_menu);
        }
    }
}
